<template>
	<div>test</div>
	<button @click="send">send</button>
</template>
<script lang="ts" setup>
import { BaseHttp, HttpRequest, RequestError } from "@pkg"

RequestError.registoyError("401", message => {
	alert(message + "401错误处理")
})
RequestError.registoyError("404", message => {
	alert(message + "404错误处理")
})

BaseHttp.createInstance(
	{ timeout: 6000 },
	{
		responseInterceptors: {
			success(res) {
				console.log("自定义响应成功!", res.data)
				if (res.data.code !== 200) {
					new RequestError(res.data.code.toString(), res.data.message)
				}
				return res.data
			},
			error(err) {
				console.log(err, "自定义响应失败")
				return Promise.resolve("失败了")
			},
		},
	}
)

const send = () => {
	try {
		new HttpRequest("https://api.apiopen.top/api/getI1mages")
			.setBaseUrl("")
			.get()
			.then(res => {
				console.log(res, "rrrrrrrrrrr")
			})
	} catch (error) {
		console.log(error, "ddddddddddd")
	}
}
</script>
